/**
 * Copyright  (c) 2009-2013 XLab,  Org. 
 * All  rights  reserved. 
 */
package org.xlab.baseframework.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.xlab.baseframework.domain.DefaultRootUserDomain;
import org.xlab.baseframework.domain.DefaultUserDomain;
import org.xlab.baseframework.domain.ISystemRootUserDomain;
import org.xlab.baseframework.domain.ISystemUserDomain;
import org.xlab.baseframework.exception.RootUserNotFoundException;
import org.xlab.baseframework.service.spi.IUserService;

/**
 * <p>
 * 系统用户服务接口默认实现
 * </p>
 * 
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0 Sep 10, 2010
 * @since 1.0.0
 * 
 */
@Service
public class DefaultUserServiceImpl implements IUserService {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 7762718581563507099L;

	private static Map<String, ISystemUserDomain> users;

	/**
	 * 
	 */
	public DefaultUserServiceImpl() {
		super();
		users = new HashMap<String, ISystemUserDomain>();
	}

	public ISystemUserDomain createOrReplaceUser(String userCode,
			String userName, String realName, String userEmail) {
		DefaultUserDomain newUser = new DefaultUserDomain(userCode, userName, realName,
				userEmail);
		users.put(userCode, newUser);
		return newUser;
	}

	/**
	 * @see org.xlab.baseframework.service.spi.IUserService#getSystemRootUser()
	 */
	public ISystemRootUserDomain getSystemRootUser()
			throws RootUserNotFoundException {
		DefaultRootUserDomain rootUserDomain = new DefaultRootUserDomain();
		rootUserDomain.setRealName("MaKuBEX");
		rootUserDomain.setUserCode("MaKuBEX");
		rootUserDomain.setUserName("MaKuBEX");
		rootUserDomain.setUserEmail("makubexnet@gmail.com");
		return rootUserDomain;
	}

	public ISystemUserDomain getUser(String userCode) {
		return users.get(userCode);
	}
}
